module.exports = function (grunt) {
    // Project configuration.
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        clean: {
            pub: ['js/pub/*', 'js/dev/thirdjs/*']
        },
        copy: {
            thirdjs: {
                files: [{
                    expand: true,
                    cwd: "bower_components/jquery",
                    src: "jquery.js",
                    dest: "js/dev/thirdjs/"
                }, {
                    expand: true,
                    cwd: "bower_components/requirejs",
                    src: "require.js",
                    dest: "js/dev/thirdjs/"
                }, {
                    expand: true,
                    cwd: "bower_components/bootstrap/dist/css",
                    src: ["bootstrap.css","bootstrap-theme.css"],
                    dest: "css/"
                }, {
                    expand: true,
                    cwd: "bower_components/bootstrap/fonts",
                    src: "*.*",
                    dest: "fonts/"
                }, {
                    expand: true,
                    cwd: "bower_components/bootstrap/dist/js",
                    src: "bootstrap.js",
                    dest: "js/dev/thirdjs/"
                }]
            }
        },
        less: {
            main: {
                expand: true,
                src: ['css/*.less'],
                desc: 'css',
                ext: '.css'
            }
        },
        // uglify: {
        //     options: {
        //         banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
        //     },
        //     build: {
        //         src: 'src/<%= pkg.name %>.js',
        //         dest: 'build/<%= pkg.name %>.min.js'
        //     }
        // }
        uglify: {
            build: {
                options: {report: "min"},
                files: [{
                    expand: true,
                    cwd: 'js/dev',
                    src: '**/*.js',
                    dest: 'js/pub/'
                }]

            }
        },
        watch: {
            start: {
                files: ['css/*.less'],
                tasks:['less:main']
            }
        }
    });

    // 加载包含 "clean" 任务的插件
    grunt.loadNpmTasks('grunt-contrib-clean');

    // 加载包含 "copy" 任务的插件
    grunt.loadNpmTasks('grunt-contrib-copy');

    // 加载包含 "less" 任务的插件。
    grunt.loadNpmTasks('grunt-contrib-less');

    // 加载包含 "uglify" 任务的插件。
    grunt.loadNpmTasks('grunt-contrib-uglify');

    // 加载包含 "watch" 任务的插件。
    grunt.loadNpmTasks('grunt-contrib-watch');

    // 默认被执行的任务列表。
    grunt.registerTask('default', 'myUglify');
    grunt.registerTask('myCopy', ['clean', 'copy']);
    grunt.registerTask('myUglify', ['clean', 'copy', 'uglify']);

    // 为指定的事件添加监听器
    grunt.event.on('watch', function (action, filepath, target) {
        grunt.log.writeln(target + ":" + filepath + " has " + action);
    });
};